package com.example.scene;

import cn.hutool.core.util.ClassLoaderUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.example.data.BWebSiteData;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

public class HelloController {


    @FXML
    private ImageView photo;
    @FXML
    private TextField number;

    @FXML
    protected void onHelloButtonClick() {
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                String baseUrl="https://api.bilibili.com/x/web-interface/view?bvid=";
                String BVId=number.getText();// BV1dP4y1t7hV
                baseUrl+=BVId;
                String result = HttpUtil.get(baseUrl);
                BWebSiteData bWebSiteData = JSONUtil.toBean(result, BWebSiteData.class);
                String imgUrl=bWebSiteData.getData().getPic();
                Image image = new Image(imgUrl);
                photo.setImage(image);
            }
        });
    }
}